package net.src.socket3;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.Socket;

public class ServerReaderThead implements Runnable{
    private Socket socket;
    public ServerReaderThead(Socket socket){
        this.socket = socket;
    }
    @Override
    //run方法不准把异常抛出去,要自己try一下
    public void run() {
        try {
            InputStream is = socket.getInputStream();

            BufferedReader br = new BufferedReader(new InputStreamReader(is));
            String msg;
            while((msg = br.readLine())!=null){
                System.out.println(socket.getRemoteSocketAddress() + "发送了:" + msg);
            }
        } catch (Exception e) {
            //下线逻辑,提示用户的下线
            System.out.println(socket.getRemoteSocketAddress() + "下线了!");
        }
    }
}
